package com.imooc.dynamic.springboot;

import com.imooc.dynamic.raw.DataSourceContext;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import java.util.Map;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
public class SpringDynamicDataSource extends AbstractRoutingDataSource {

    public SpringDynamicDataSource(Map<Object, Object> targetDataSources) {
        super.setTargetDataSources(targetDataSources);
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return DataSourceContext.getCurrentDb();
    }
}
